package com.admin.service;

import com.admin.bean.Banner;
import com.admin.dbdao.BannerAdminDao;
import com.data.util.CheckDataUtils;
import com.data.util.DatabaseIdUtils;
import com.data.util.DateUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * banner图管理的服务层
 *
 * @author: HingLo
 * @create 2017-09-26 14:31
 **/
@Service
public class BannerAdminService {
    private static Logger logger = Logger.getLogger(BannerAdminService.class);
    @Autowired
    private BannerAdminDao bannerAdminDao;


    public List<?> findAllBannerTypeService() {
        return bannerAdminDao.findAllBannerTypeDao();
    }

    public boolean submitBannerAddAdminService(Banner banner, String date) {
        date = date.trim();
        if (!CheckDataUtils.stringUtils(banner.getId())){
            banner.setId(DatabaseIdUtils.getDataIdOne());
        }
        banner.setCtime(new Date());
        if (banner.getEndtime() == null) {
            banner.setEndtime(DateUtils.stringToDate(date));
        }
        return bannerAdminDao.submitBannerAddAdminDao(banner);
    }

    /**
     * 过期删除
     *
     * @param id
     * @return
     */
    public boolean delBannerAdminService(String id) {

        if (CheckDataUtils.stringUtilsID(id)) {
            id = id.trim();
            return bannerAdminDao.delBannerAdminDao(id);
        }

        return false;
    }

    /**
     * 查看图片
     *
     * @param id
     * @return
     */
    public Banner lookBannerIconService(String id) {
        id = id.trim();
        List<Banner> list = bannerAdminDao.lookBannerIconDao(id);
        return list.isEmpty() ? null : list.get(0);
    }

}
